package com.uenpay.util.imageloader;

import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;

/**
 * Created by liulou on 2016/11/17.
 * desc:
 */

public class ImageLoader {
    private String url;
    private int resId;
    private Uri uri;
    private int placeHolder; //placeholder when fail to load pics
    private ImageView imgView; //ImageView instantce
    private int wifiStrategy;//load strategy ,wheather under wifi
    private boolean isCache;//是否使用缓存
    private String key;//保存图片的key
    /**
     * 是否加载为圆形图片
     */
    private boolean isCircle;

    /**
     * 设置圆角图片radius
     */
    private int roundRadius;

    private ImageLoader(Builder builder) {
        this.url = builder.url;
        this.resId = builder.resId;
        this.placeHolder = builder.placeHolder;
        this.imgView = builder.imgView;
        this.wifiStrategy = builder.wifiStrategy;
        this.isCircle = builder.isCircle;
        this.roundRadius = builder.roundRadius;
        this.isCache = builder.isCache;
        this.key = builder.key;
    }


    public String getUrl() {
        return url;
    }

    public int getPlaceHolder() {
        return placeHolder;
    }

    public ImageView getImgView() {
        return imgView;
    }

    public int getWifiStrategy() {
        return wifiStrategy;
    }

    public int getResId() {
        return resId;
    }

    public Uri getUri() {
        return uri;
    }

    public boolean isCircle() {
        return isCircle;
    }

    public int getRoundRadius() {
        return roundRadius;
    }

    public boolean isCache(){
        return isCache;
    }

    public String getKey() {
        return key;
    }

    public static class Builder {
        private String url;
        private int resId;
        private Uri uri;
        private int placeHolder;
        private ImageView imgView;
        private int wifiStrategy;
        private boolean isCircle;
        private int roundRadius;
        private boolean isCache;
        private String key;

        public Builder() {
            this.wifiStrategy = ImageLoaderUtil.LOAD_STRATEGY_NORMAL;
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder url(int resId) {
            this.resId = resId;
            return this;
        }

        public Builder url(Uri uri) {
            this.uri = uri;
            return this;
        }

        public Builder isCircle(boolean isCircle) {
            this.isCircle = isCircle;
            return this;
        }

        public Builder roundRadius(int radius) {
            this.roundRadius = radius;
            return this;
        }

        public Builder placeHolder(int placeHolder) {
            this.placeHolder = placeHolder;
            return this;
        }

        public Builder imgView(ImageView imgView) {
            this.imgView = imgView;
            return this;
        }

        public Builder strategy(int strategy) {
            this.wifiStrategy = strategy;
            return this;
        }

        public ImageLoader build() {
            return new ImageLoader(this);
        }

        public Builder isCache(boolean isCache){
            this.isCache = isCache;
         return this;
        }

        public Builder setKey(String key){
            this.key = key;
            return this;
        }

    }
}
